package org.mayanjun.code.dalint.helper;

import java.util.*;

/**
 * Read-only to not-same package
 *
 * @author mayanjun(7/3/16)
 */
public class ReadOnlyMap<K, V> implements Map<K, V> {

    private Map<K, V> container;

    public ReadOnlyMap() {
        this.container = new HashMap<K, V>();
    }

    @Override
    public int hashCode() {
        return container.hashCode();
    }

    @Override
    public boolean equals(Object o) {
        return container.equals(o);
    }

    @Override
    public int size() {
        return container.size();
    }

    @Override
    public boolean isEmpty() {
        return container.isEmpty();
    }

    @Override
    public boolean containsKey(Object key) {
        return container.containsKey(key);
    }

    @Override
    public boolean containsValue(Object value) {
        return container.containsValue(value);
    }

    @Override
    public V get(Object key) {
        return container.get(key);
    }

    @Override
    public V put(K key, V value) {
        throw new UnsupportedOperationException("Read only map, can not be modified");
    }

    @Override
    public V remove(Object key) {
        throw new UnsupportedOperationException("Read only map, can not be modified");
    }

    @Override
    public void putAll(Map<? extends K, ? extends V> m) {
        throw new UnsupportedOperationException("Read only map, can not be modified");
    }

    @Override
    public void clear() {
        throw new UnsupportedOperationException("Read only map, can not be modified");
    }

    @Override
    public Set<K> keySet() {
        return container.keySet();
    }

    @Override
    public Collection<V> values() {
        return new ReadOnlyArrayList<V>(container.values());
    }

    @Override
    public Set<Entry<K, V>> entrySet() {
        return container.entrySet();
    }

    V putInternal(K key, V value) {
        return container.put(key, value);
    }

    void putAllInternal(Map<? extends K, ? extends V> m) {
        container.putAll(m);
    }

    V removeInternal(Object key) {
        return container.remove(key);
    }
}
